<%@page import="com.crossriver.crgis.cofo.util.PaymentBean"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>

<%@ include file="/init.jsp"%>
<portlet:defineObjects />

<portlet:resourceURL var="ajaxCallResourceURL" />
<portlet:renderURL var="paymentstatusURL">
	<portlet:param name="jspPage" value="/html/payments/payment-status.jsp" />
</portlet:renderURL>

<%
PaymentBean payBean = (PaymentBean)request.getAttribute("payBean");
%>

<div id="main">
	<h1>Payment - Online Application(s)</h1>
  <div class="content"> 
  	<span class="title">Payment Mode - InterSwitch</span>
    <hr>
    <table width="100%" bgcolor="#DFFFDF" id="iswitchtab">
    <tr>
    	<td><img src="${renderRequest.contextPath}/images/info.png" width="40" height="40"></td>
      <td> 
      	The transaction fee shown is charged by the payment gateway. Please, do not 
        close the browser until you complete the payment.You will recieve a confirmatory 
        message when you complete the payment. 
     	</td>
    </tr>
    </table><br>
    <form name="form_InterswitchPayentMode" method="post" 
    		action="https://testwebpay.interswitchng.com/test_paydirect/pay" id="form_InterswitchPayentMode">
    <table width="85%" id="tfee" align="center" border="1">
      <tr>
          <td width="40%">Transaction Reference No:</td>
          
          <td align="right" width="30%"><strong><input type="text" id="txn_ref" readonly="true" value="<%= payBean.getTxn_no()  %>" name="" class="ixtra"/></strong></td>
          <td rowspan="5" width="30%" align="center"><img src="${renderRequest.contextPath}/images/interswitchvervemastercard.png"></td>
      </tr>
      <tr>
          <td>Customer's Full Name:</td>
          <td align="right" ><strong><input type="text" id="cust_name" 
          	readonly="true" value="<%=payBean.getCust_name() %>" name="" class="ixtra"/></strong></td>
      </tr>
      
      <tr>
     		<td>Amount:</td>
     		<% 
     		%>
     		<td align="right"><strong><input type="text" id="displayAmount" readonly="true" value="&#8358; <%=payBean.getPaymentAmount() %>" name="" class="ixtra"/></strong></td>
      </tr>
      <tr>
	      <td>Transaction Fee:</td>
	      <td align="right" ><strong><input type="text" id="displayFees" readonly="true" value="&#8358; <%=payBean.getTransactionFees() %>" name="" class="ixtra"/></strong></td>
      </tr>
      <tr bgcolor="#C6FFEC">
	      <td>TOTAL:</td>
	      <td align="right"><strong>&#8358; <%=payBean.getTotalAmount() %></strong></td>
      </tr>
      <tr>
      	<td colspan="3" align="center">
      		<input name="" type="button" value="Back " onClick="history.go(-1); return true;">
			    <input type="button" value="Pay Now!" onClick="logTransaction();">
			    <input name="" type="button" value="Cancel" onClick="paymentCancel();">
      	</td>
      </tr>
    </table>
    <p>
			 <input type="hidden" id="product_id" value="<%=payBean.getProduct_id() %>" name="product_id"/> 
			<input type="hidden" id="amount" value="<%=payBean.getS_totalAmount() %>" name="amount"/> 
			<input type="hidden" id="currency" value="<%=payBean.getCurrency() %>" name="currency"/> 
			<input type="hidden" id="payment_params" value="0" name="payment_params"/> 
			<input type="hidden" id="hash" value="<%= payBean.getHash() %>" name="hash"/>
			<input type="hidden" id="site_redirect_url" value="<%=payBean.getSite_redirect_url() %>" name="site_redirect_url"/> 
			<input type="hidden" id="site_name" value="<%= payBean.getSite_name()%>" name="site_name"/> 
			<input type="hidden" id="cust_id" value="<%=payBean.getCust_id() %>" name="cust_id"/> 
			<input type="hidden" id="cust_id_desc" value="Email" name="cust_id_desc"/> 
			<input type="hidden" id="cust_name" value="<%=payBean.getCust_name() %>" name="cust_name"/> 
			<input type="hidden" id="cust_name_desc" value="Customer Name" name="cust_name_desc"/>
			<input type="hidden" id="txn_ref" value="<%= payBean.getTransactionRef()%>" name="txn_ref"/> 
			<input type="hidden" id="pay_item_id" value="<%= payBean.getPay_item_id()%>" name="pay_item_id"/> 
			<input type="hidden" id="pay_item_name" value=" <%= payBean.getPay_item_name()%>" name="pay_item_name"/> 
			<input type="hidden" id="local_date_time" value="<%=payBean.getLocal_date_time() %>" name="local_date_time"/>  
			
			<!-- <input type="hidden" id="product_id" value="3987" name="product_id"/>
			<input type="hidden" id="amount" value="1000000" name="amount"/>
			<input type="hidden" id="currency" value="566" name="currency"/>
			<input type="hidden" id="payment_params" value="0" name="0"/>
			<input type="hidden" id="hash" value="1ACD9B0108CB1F0492B4C52BFB8F5FF0193145FF850A34747BB5E3856A1946F29C04D525F2E2DBBD347B0843CCA2614B42A0B9EB66796711E828989CE1E962CB" name="hash"/>
			<input type="hidden" id="site_redirect_url" value="http://www.crgia.crossriverstate.gov.ng/group/crgia/payments?p_auth=o7LCkBQc&echo=Payment&p_p_id=Payments_WAR_CRGISTransactionCofOportlet&p_p_lifecycle=1&p_p_state=normal&p_p_mode=view&p_p_col_id=column-2&p_p_col_count=1&_Payments_WAR_CRGISTransactionCofOportlet_javax.portlet.action=processDirectPayResponse&transactionNo=7ac3c1fb-60a8-45f8-9625-48b6b4b4edd9" name="site_redirect_url"/>
			<input type="hidden" id="site_name" value="http://www.crgia.crossriverstate.gov.ng" name="site_name"/>
			<input type="hidden" id="cust_id" value="woleadetiba@gmail.com" name="cust_id"/>
			<input type="hidden" id="cust_id_desc" value="Email" name="cust_id_desc"/>
			<input type="hidden" id="cust_name" value="OLUWOLE OLADIMEJI ADETIBA" name="cust_name"/>
			<input type="hidden" id="cust_name_desc" value="Customer Name" name="cust_name_desc"/>
			<input type="hidden" id="txn_ref" value="CRGIA-2012-012331-2012.10.24.10.57" name="txn_ref"/>
			<input type="hidden" id="pay_item_id" value="101" name="pay_item_id"/>
			<input type="hidden" id="pay_item_name" value=" Application Fees CERTIFICATION-INDIVIDUAL" name="pay_item_name"/>
			<input type="hidden" id="local_date_time" value="24-Oct-12 08:10:57" name="local_date_time"/> -->

	</form>
	</div>
</div>

<liferay-portlet:actionURL name="cancel" var="cancel"></liferay-portlet:actionURL>
<liferay-portlet:actionURL name="logTransB4Interswitch" var="logTransB4Interswitch"></liferay-portlet:actionURL>



<form name="<portlet:namespace/>paymentCancel_fm" method="post"	id="<portlet:namespace/>paymentCancel_fm" action="<%=cancel.toString()%>">
</form>

<form name="<portlet:namespace/>logTransB4Interswitch_fm" method="post"	id="<portlet:namespace/>logTransB4Interswitch_fm" action="<%=logTransB4Interswitch.toString()%>">
</form>

<script type="text/javascript">
<!--
	
	function paymentCancel()
	{
		document.forms["<portlet:namespace/>paymentCancel_fm"].submit();
	}


	function logTransaction()
	{
		//alert('before submit');
		////<portlet:namespace/>logTransaction('LOGTRANS');
		//alert('after submit then sending to interswitch');
		document.forms["form_InterswitchPayentMode"].submit();
		//alert('after submission to interswitch');
	}

//-->
</script>

<aui:script>

	Liferay.provide(
		window,
		'<portlet:namespace />logTransaction', //this is the method name
		function(logTrans ) { //parameters counld be passed to the functions
			var A = AUI(); 
				var url = '<%= ajaxCallResourceURL.toString() %>';
				A.io.request(
					url,
					{
						//data to be sent to server
						data: {
							<portlet:namespace />operationType: logTrans
						},
						dataType: 'json',

						on: {
							failure: function() {
							},

							success: function(event, id, obj) {
								var instance = this;


								//JSON Data coming back from Server
								
								var message = instance.get('responseData');
								

								if (message) { 
									
									var site_redirect_url= document.getElementById('site_redirect_url');
									site_redirect_url.value=message.site_url;
									
									//alert(site_redirect_url.value);
									
									document.forms["form_InterswitchPayentMode"].submit();
											
								}
								else {
									
									alert('no data back from server');
								}
							}

						}
					}

				); //END of io Request

		},
		['aui-io']
	);  //End of Provide 1
	
	
	
</aui:script>
